home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / gnucdiff / diff.h < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-16  |  10.2 KB  |  368 lines

  1. /* Shared definitions for GNU DIFF
  2.    Copyright (C) 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU DIFF.
  5.  
  6. GNU DIFF is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY.  No author or distributor
  8. accepts responsibility to anyone for the consequences of using it
  9. or for whether it serves any particular purpose or works at all,
  10. unless he says so in writing.  Refer to the GNU DIFF General Public
  11. License for full details.
  12.  
  13. Everyone is granted permission to copy, modify and redistribute
  14. GNU DIFF, but only under the conditions described in the
  15. GNU DIFF General Public License.   A copy of this license is
  16. supposed to have been given to you along with GNU DIFF so you
  17. can know your rights and responsibilities.  It should be in a
  18. file named COPYING.  Among other things, the copyright notice
  19. and this notice must be preserved on all copies.  */
  20.  
  21.  
  22. #include <ctype.h>
  23. #include <stdio.h>
  24. #include <sys/types.h>
  25.  
  26. #if !defined(MSDOS)
  27. #include <sys/file.h>
  28. #endif    /* MSDOS */
  29.  
  30. #include <sys/stat.h>
  31.  
  32. #ifdef USG
  33. #include <time.h>
  34.  
  35. #if !defined(MSDOS)
  36. #include <dirent.h>
  37. #endif /* MSDOS */
  38.  
  39. #include <fcntl.h>
  40. #define direct dirent
  41. #else
  42. #include <sys/time.h>
  43. #include <sys/dir.h>
  44. #endif
  45.  
  46. #ifdef USG
  47. /* Define needed BSD functions in terms of sysV library.  */
  48.  
  49. #define bcopy(s,d,n)    memcpy((d),(s),(n))
  50. #define bcmp(s1,s2,n)    memcmp((s1),(s2),(n))
  51. #define bzero(s,n)    memset((s),0,(n))
  52.  
  53. #if !defined(MSDOS)
  54. #define dup2(f,t)    (close(t),fcntl((f),F_DUPFD,(t)))
  55. #endif
  56.  
  57. #define vfork    fork
  58. #define index    strchr
  59. #define rindex    strrchr
  60. #endif
  61.  
  62. #ifdef MSDOS
  63. #include <process.h>
  64. #include <stdlib.h>
  65. #endif /* MSDOS */
  66.  
  67. #include <errno.h>
  68.  
  69. #if !defined(MSDOS)
  70. extern int      errno;
  71. extern int      sys_nerr;
  72. extern char    *sys_errlist[];
  73. #endif
  74.  
  75. #define    EOS        (0)
  76. #define    FALSE        (0)
  77. #define TRUE        1
  78.  
  79. #if !defined(min)
  80. #define min(a,b) ((a) <= (b) ? (a) : (b))
  81. #define max(a,b) ((a) >= (b) ? (a) : (b))
  82. #endif /* MSDOS */
  83.  
  84. #ifndef PR_FILE_NAME
  85. #define PR_FILE_NAME "/bin/pr"
  86. #endif
  87.  
  88. /* Support old-fashioned C compilers.  */
  89. #if defined (__STDC__) || defined (__GNUC__)
  90. #if !defined(MSDOS)
  91. #include "limits.h"
  92. #else
  93. #include <limits.h>
  94. #endif    /* MSDOS */
  95. #else
  96. #define INT_MAX 2147483647
  97. #define CHAR_BIT 8
  98. #endif
  99.  
  100. #if defined(MSDOS)
  101. #ifdef INT_MAX
  102. #undef INT_MAX
  103. #include <limits.h>
  104. #endif
  105. #if !defined(MAKING_PROTO_H)
  106. #include "proto.h"
  107. #endif
  108. #include <malloc.h>
  109. #include <io.h>
  110. #include <memory.h>
  111. extern int getopt(int nargc,char **nargv,char *ostr);
  112. #endif
  113.  
  114. /* Support old-fashioned C compilers.  */
  115. #if !defined (__STDC__) && !defined (__GNUC__) || defined(MSDOS)
  116. #define const
  117. #endif
  118.  
  119. /* Variables for command line options */
  120.  
  121. #ifndef GDIFF_MAIN
  122. #define EXTERN extern
  123. #else
  124. #define EXTERN
  125. #endif
  126.  
  127. enum output_style {
  128.   /* Default output style.  */
  129.   OUTPUT_NORMAL,
  130.   /* Output the differences with lines of context before and after (-c).  */
  131.   OUTPUT_CONTEXT,
  132.   /* Output the differences as commands suitable for `ed' (-e).  */
  133.   OUTPUT_ED,
  134.   /* Output the diff as a forward ed script (-f).  */
  135.   OUTPUT_FORWARD_ED,
  136.   /* Like -f, but output a count of changed lines in each "command" (-n). */
  137.   OUTPUT_RCS };
  138.  
  139. EXTERN enum output_style output_style;
  140.  
  141. /* Number of lines of context to show in each set of diffs.
  142.    This is zero when context is not to be shown.  */
  143. EXTERN int      context;
  144.  
  145. /* Consider all files as text files (-a).
  146.    Don't interpret codes over 0177 as implying a "binary file".  */
  147. EXTERN int    always_text_flag;
  148.  
  149. /* Ignore changes in horizontal whitespace (-b).  */
  150. EXTERN int      ignore_space_change_flag;
  151.  
  152. /* Ignore all horizontal whitespace (-w).  */
  153. EXTERN int      ignore_all_space_flag;
  154.  
  155. /* Ignore changes that affect only blank lines (-B).  */
  156. EXTERN int      ignore_blank_lines_flag;
  157.  
  158. /* Ignore changes that affect only lines matching this regexp (-I).  */
  159. EXTERN char    *ignore_regexp;
  160.  
  161. /* Result of regex-compilation of `ignore_regexp'.  */
  162. EXTERN struct re_pattern_buffer ignore_regexp_compiled;
  163.  
  164. /* 1 if lines may match even if their lengths are different.
  165.    This depends on various options.  */
  166. EXTERN int      length_varies;
  167.  
  168. /* Ignore differences in case of letters (-i).  */
  169. EXTERN int      ignore_case_flag;
  170.  
  171. /* Regexp to identify function-header lines (-F).  */
  172. EXTERN char    *function_regexp;
  173.  
  174. /* Result of regex-compilation of `function_regexp'.  */
  175. EXTERN struct re_pattern_buffer function_regexp_compiled;
  176.  
  177. /* Report files compared that match (-s).
  178.    Normally nothing is output when that happens.  */
  179. EXTERN int      print_file_same_flag;
  180.  
  181. /* character that ends a line.  Currently this is always `\n'.  */
  182. EXTERN char     line_end_char;
  183.  
  184. /* Output the differences with exactly 8 columns added to each line
  185.    so that any tabs in the text line up properly (-T).  */
  186. EXTERN int    tab_align_flag;
  187.  
  188. /* Expand tabs in the output so the text lines up properly
  189.    despite the characters added to the front of each line (-t).  */
  190. EXTERN int    tab_expand_flag;
  191.  
  192. /* In directory comparison, specify file to start with (-S).
  193.    All file names less than this name are ignored.  */
  194. EXTERN char    *dir_start_file;
  195.  
  196. /* If a file is new (appears in only one dir)
  197.    include its entire contents (-N).
  198.    Then `patch' would create the file with appropriate contents.  */
  199. EXTERN int    entire_new_file_flag;
  200.  
  201. /* Pipe each file's output through pr (-l).  */
  202. EXTERN int    paginate_flag;
  203.  
  204. /* String containing all the command options diff received,
  205.    with spaces between and at the beginning but none at the end.
  206.    If there were no options given, this string is empty.  */
  207. EXTERN char *    switch_string;
  208.  
  209. /* Nonzero means use heuristics for better speed.  */
  210. EXTERN int    heuristic;
  211.  
  212. /* Name of program the user invoked (for error messages).  */
  213. EXTERN char *    program;
  214.  
  215. /* The result of comparison is an "edit script": a chain of `struct change'.
  216.    Each `struct change' represents one place where some lines are deleted
  217.    and some are inserted.
  218.    
  219.    LINE0 and LINE1 are the first affected lines in the two files (origin 0).
  220.    DELETED is the number of lines deleted here from file 0.
  221.    INSERTED is the number of lines inserted here in file 1.
  222.  
  223.    If DELETED is 0 then LINE0 is the number of the line before
  224.    which the insertion was done; vice versa for INSERTED and LINE1.  */
  225.  
  226. struct change
  227. {
  228.   struct change *link;        /* Previous or next edit command  */
  229.   int inserted;            /* # lines of file 1 changed here.  */
  230.   int deleted;            /* # lines of file 0 changed here.  */
  231.   int line0;            /* Line number of 1st deleted line.  */
  232.   int line1;            /* Line number of 1st inserted line.  */
  233.   char ignore;            /* Flag used in context.c */
  234. };
  235.  
  236. /* Structures that describe the input files.  */
  237.  
  238. /* Data on one line of text.  */
  239.  
  240. struct line_def {
  241.     char        *text;
  242.     int         length;
  243.     unsigned    hash;
  244. };
  245.  
  246. /* Data on one input file being compared.  */
  247.  
  248. struct file_data {
  249.     int             desc;    /* File descriptor  */
  250.     char           *name;    /* File name  */
  251.     struct stat     stat;    /* File status from fstat()  */
  252.     int             dir_p;    /* 1 if file is a directory  */
  253.  
  254.     /* Buffer in which text of file is read.  */
  255. #if !defined(MSDOS)
  256.     char *        buffer;
  257.  
  258.     /* Allocated size of buffer.  */
  259.     int            bufsize;
  260.  
  261.     /* Number of valid characters now in the buffer. */
  262.     long int            buffered_chars;
  263. #else    /* MSDOS */
  264.     char huge *buffer;
  265.  
  266.     /* Allocated size of buffer.  */
  267.     long int        bufsize;
  268.  
  269.     /* Number of valid characters now in the buffer. */
  270.     long int            buffered_chars;
  271. #endif    /* MSDOS */
  272.  
  273.     /* Array of data on analyzed lines of this chunk of this file.  */
  274.     struct line_def *linbuf;
  275.  
  276.     /* Allocated size of linbuf array (# of elements).  */
  277.     int            linbufsize;
  278.  
  279.     /* Number of elements of linbuf containing valid data. */
  280.     int            buffered_lines;
  281.  
  282.     /* Pointer to end of prefix of this file to ignore when hashing. */
  283.     char *prefix_end;
  284.  
  285.     /* Count of lines in the prefix. */
  286.     int prefix_lines;
  287.  
  288.     /* Pointer to start of suffix of this file to ignore when hashing. */
  289.     char *suffix_begin;
  290.  
  291.     /* Count of lines in the suffix. */
  292.     int suffix_lines;
  293.  
  294.     /* Vector, indexed by line number, containing an equivalence code for
  295.        each line.  It is this vector that is actually compared with that
  296.        of another file to generate differences. */
  297.     int           *equivs;
  298.  
  299.     /* Vector, like the previous one except that
  300.        the elements for discarded lines have been squeezed out.  */
  301.     int           *undiscarded;
  302.  
  303.     /* Vector mapping virtual line numbers (not counting discarded lines)
  304.        to real ones (counting those lines).  Both are origin-0.  */
  305.     int           *realindexes;
  306.  
  307.     /* Total number of nondiscarded lines. */
  308.     int            nondiscarded_lines;
  309.  
  310.     /* Vector, indexed by real origin-0 line number,
  311.        containing 1 for a line that is an insertion or a deletion.
  312.        The results of comparison are stored here.  */
  313.     char       *changed_flag;
  314.  
  315.     /* 1 if file ends in a line with no final newline. */
  316.     int            missing_newline;
  317.  
  318.     /* 1 more than the maximum equivalence value used for this or its
  319.        sibling file. */
  320.     int equiv_max;
  321.  
  322.     /* Table translating diff's internal line numbers 
  323.        to actual line numbers in the file.
  324.        This is needed only when some lines have been discarded.
  325.        The allocated size is always linbufsize
  326.        and the number of valid elements is buffered_lines.  */
  327.     int           *ltran;
  328. };
  329.  
  330. /* Describe the two files currently being compared.  */
  331.  
  332. struct file_data files[2];
  333.  
  334. /* Queue up one-line messages to be printed at the end,
  335.    when -l is specified.  Each message is recorded with a `struct msg'.  */
  336.  
  337. struct msg
  338. {
  339.   struct msg *next;
  340.   char *format;
  341.   char *arg1;
  342.   char *arg2;
  343. };
  344.  
  345. /* Head of the chain of queues messages.  */
  346.  
  347. EXTERN struct msg *msg_chain;
  348.  
  349. /* Tail of the chain of queues messages.  */
  350.  
  351. EXTERN struct msg *msg_chain_end;
  352.  
  353. /* Stdio stream to output diffs to.  */
  354.  
  355. EXTERN FILE *outfile;
  356.  
  357. /* Declare various functions.  */
  358.  
  359. void *xmalloc ();
  360. void *xrealloc ();
  361. void *xcalloc();
  362. char *concat ();
  363. void free ();
  364.  
  365. void message ();
  366. void print_message_queue ();
  367.  
  368.